#include <device/uart.h>
#include <io.h>

void uart_send(char c)
{
	while((readb(UART_LSR) & UART_LSR_EMPTY) == 0) {;}
	writeb(c, UART_DAT);
}

#define UART_CLOCK  1843200 // a common base clock
#define UART_BAUD   115200  // a common base baud

void uart_init(void)
{
	unsigned int divisor = UART_CLOCK / (16 * UART_BAUD);

	/* disable interrupt */
	writeb(0, UART_IER);

	/* Enable DLAB (set baud rate divisor)*/
	writeb(0x80, UART_LCR);
	writeb((unsigned char)divisor, UART_DLL);
	writeb((unsigned char)(divisor >> 8), UART_DLM);

	/*8 bits, no parity, one stop bit*/
	writeb(0x3, UART_LCR);

	/* 使能FIFO，清空FIFO，设置接收数据FIFO 14字节阈值*/
	writeb(0xc7, UART_FCR);
}
